export default {
	alert(title) {
		uni.showToast({
			title,
			icon: 'none'
		})
	},
	formatDate(time, format='YYYY-MM-DD HH:mm:ss') {
		const timer = time ? new Date(time) : new Date()
		const year = timer.getFullYear().toString().padStart(2, '0')
		const month = (timer.getMonth() + 1).toString().padStart(2, '0')
		const day = timer.getDate().toString().padStart(2, '0')
		const hour = timer.getHours().toString().padStart(2, '0')
		const minute = timer.getMinutes().toString().padStart(2, '0')
		const second = timer.getSeconds().toString().padStart(2, '0')
		return format.replace('YYYY', year).replace('MM', month).replace('DD', day).replace('HH', hour).replace('mm', minute).replace('ss', second)
	},
	checkUpdate(settingInfo, tips, force_update = 0) {
		if (settingInfo.version_code > uni.getSystemInfoSync().appVersionCode) {
			uni.showModal({
				title: '升级提示',
				content: force_update == 1 ? '您的版本过低，请升级' : '检测到有新版本，确定要升级吗？',
				showCancel: force_update == 1 ? false : true,
				success: (res) => {
					if (res.cancel) return;
					const sysInfo = uni.getSystemInfoSync();
					if (sysInfo.platform === 'ios') {
						plus.runtime.openURL(settingInfo.update_ios);
					} else {
						if (force_update == 1) uni.showLoading({
							title: '正在下载安装包...',
							mask: true
						})
						else this.alert('正在后台下载安装包...');
						uni.downloadFile({
							url: settingInfo.update_android,
							success: (tmpFile) => {
								if (tmpFile.statusCode === 200) {
									plus.runtime.install(tmpFile.tempFilePath);
								}
							}
						});
					}
				}
			});
		} else if (tips) this.alert('已是最新版本');
	}
}